package cn.liit.weixin.jssdk.basic;

import java.util.HashMap;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;

import cn.liit.weixin.core.config.Config;
import cn.liit.weixin.core.utils.Signature;
import name.zbq.bush.utils.DateUtil;
import name.zbq.bush.utils.RandomStringGenerator;

/**
 * jssdk配置
 * @author zhangboqi
 *
 */
public class JssdkConfig {

	/**
	 * jssdk配置参数
	 * @param url 使用jssdk页面的url
	 * @param jsapi_ticket
	 * @return 返回配置参数
	 * @throws Exception 
	 */
	public static Map<String,Object> config(String url,String jsapi_ticket) throws Exception{
		SortedMap<String,String> signParams = new TreeMap<String,String>();
		String timestamp = DateUtil.getTimeStamp();
		String nonceStr = RandomStringGenerator.getNonceStr();
		signParams.put("url", url);
		signParams.put("timestamp", timestamp);
		signParams.put("noncestr", nonceStr);
		signParams.put("jsapi_ticket", jsapi_ticket);
		Map<String,Object> result = new HashMap<String, Object>();
		result.put("signature", Signature.createSHA1Sign(signParams));
		result.put("appid", Config.appid);
		result.put("timestamp", timestamp);
		result.put("nonceStr", nonceStr);
		return result;
	}
}
